home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / PRGMANIA / BFED.10 / MENU.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  9.7 KB  |  508 lines

  1. /********************************************
  2.     file: menu.c
  3.     utility:
  4.     date: 1989
  5.     author: Jim Charlton
  6.     modifications:
  7.         1996: C. Moreau: 
  8.     comments: 
  9. *********************************************/
  10.  
  11. /********************************************
  12.     includes
  13. *********************************************/
  14. #include <stdio.h>
  15. #include <string.h>
  16.  
  17. #ifdef __PUREC__ 
  18. #include <aes.h>
  19. #include <vdi.h>
  20. #include <compend.h>
  21. #else
  22. #include <aesbind.h>
  23. #include <vdibind.h>
  24. #endif
  25.  
  26. #include "e:\proging\c\libs\malib\alert.h"
  27. #include "bufman.h"
  28. #include "dialog.h"
  29. #include "edit.h"
  30. #include "files.h"
  31. #include "init.h"
  32. #include "keys.h"
  33. #include "main.h"
  34. #include "menu.h"
  35. #include "printer.h"
  36. #include "search.h"
  37. #include "send.h"
  38. #include "slider.h"
  39. #include "wind.h"
  40.  
  41. #include "bfed_rsc.h"
  42.  
  43. /********************************************
  44.     defines
  45. *********************************************/
  46.  
  47. /********************************************
  48.     locals vars declarations & definitions
  49. *********************************************/
  50.  
  51. /********************************************
  52.     globals vars declarations
  53. *********************************************/
  54. char moderp[15];
  55. char modein[15];
  56. OBJECT *menu;
  57.  
  58. /********************************************
  59.     locals functions declarations
  60. *********************************************/
  61. static void handle_file(int itemid);
  62. static void handle_edit(int itemid);
  63. static void handle_search(int itemid);
  64. static void handle_windows(int itemid);
  65. static void handle_desk(int itemid);
  66. static void handle_options(int itemid);
  67.  
  68. /********************************************
  69.     globals functions definitions
  70. *********************************************/
  71. /*
  72.     name: do_menu
  73.     utility: determines which menu was selected and calls the
  74.         appropriate routine to handle the item selected. 
  75.     comment: 
  76.     parameters:
  77.     return:
  78.     date: 1989
  79.     author: Jim Charlton
  80.     modifications:
  81.         1995: C.Moreau: 
  82. */
  83. void do_menu(int menuid, int itemid)
  84. {
  85.     switch(menuid)
  86.     {
  87.         case DESK:
  88.             handle_desk(itemid);
  89.             break;
  90.         case FILE:
  91.             handle_file(itemid);
  92.             break;
  93.         case EDIT:
  94.             handle_edit(itemid);
  95.             break;
  96.         case SEARCH:
  97.             handle_search(itemid);
  98.             break;
  99.         case WINDOWS:
  100.             handle_windows(itemid);
  101.             break;
  102.         case OPTIONS:
  103.             handle_options(itemid);
  104.             break;
  105.     }
  106.     menu_tnormal(menu, menuid, UNHIGHLIGHT);
  107. }
  108.  
  109. /*
  110.     name: handle_desk
  111.     utility:  
  112.     comment: 
  113.     parameters:
  114.     return:
  115.     date: 1989
  116.     author: Jim Charlton
  117.     modifications:
  118.         1995: C.Moreau: 
  119. */
  120. static void handle_desk(int itemid)
  121. {
  122.     switch(itemid)
  123.     {
  124.         case ABOUT:
  125.             open_dialog(DINFO);    /* open form */
  126.             break;
  127.     }
  128. }
  129.  
  130. /*
  131.     name: handle_file
  132.     utility: performs the appropriate action for the menu item selected. 
  133.     comment: 
  134.     parameters:
  135.     return:
  136.     date: 1989
  137.     author: Jim Charlton
  138.     modifications:
  139.         1995: C.Moreau: 
  140.         10 may 96: C. Moreau: Take off fileselector in New file function
  141. */
  142. static void handle_file(int itemid)
  143. {
  144.     const int thewin_kind =   UPARROW | DNARROW | VSLIDE | SIZER |    \
  145.                              MOVER | FULLER | CLOSER | NAME |         \
  146.                              INFO | SMALLER;
  147.     windowptr    thewin=thefrontwin;
  148.     linkbufptr    bufptr;
  149.  
  150.     switch(itemid)
  151.     {
  152.         case NEW:    /* opens a new window with associated file  */
  153.             thewin = window_new(thewin_kind);
  154.             
  155.             if(thewin) /* abort if no more window handles */
  156.             {
  157.                 bufptr = addmember(thewin);
  158.                 if (!bufptr)    /* if no buffer allocated */
  159.                 {
  160.                     window_resources_dispose(thewin);
  161.                     rsc_alert(NOMEM_4);
  162.                 }
  163.                 else
  164.                 {
  165.                     bufptr->inuse = 1;
  166.                     thewin->flen = 1;
  167.                     ins = TRUE;
  168.                     thewin->prot = FALSE;
  169.                     update_menu();
  170.                     window_open(thewin);
  171.                 }
  172.             }
  173.             else
  174.             {
  175.                 rsc_alert(NOWIND);
  176.             }
  177.             break;
  178.         case OPEN:
  179.             thewin = window_new(thewin_kind);
  180.  
  181.             if (thewin) /* abort if no more window handles */
  182.             {
  183.                 char *string;
  184.     
  185.                 rsrc_gaddr(R_STRING, S_LOADFILE, &string);
  186.                 if (getfile(thewin, string)
  187.                     && read_file(thewin))
  188.                     window_open(thewin);
  189.                 else
  190.                     window_resources_dispose(thewin);
  191.             }
  192.             break;
  193.         case SAVE:
  194.             if (thewin)
  195.                 if (!thewin->form)
  196.                     save_file(thewin);
  197.             break;
  198.         case SAVEAS:
  199.              if (thewin)
  200.                  if (!thewin->form)
  201.                     write_file(thewin);
  202.             break;
  203.         case CLOSE:
  204.             if (thewin)
  205.                 if (!thewin->form)
  206.                 {
  207.                     dispose_buf(thewin);
  208.                     window_dispose(thewin);
  209.                 }
  210.             break;
  211.         case DELETE:
  212.             delfile();
  213.             break;
  214.         case SPACE:
  215.             open_dialog(DDISK);
  216.             break;
  217.         case PRINT:
  218.             if (thewin)
  219.                 if (!thewin->form)
  220.                     print(thewin);
  221.             break;
  222.        case SETPRINT:
  223.            open_dialog(DPRINT);
  224.             break;
  225.         case QUIT:
  226.             shutdown(0);
  227.             break;
  228.     }
  229. }
  230.  
  231. /*
  232.     name: handle_edit
  233.     utility: performs the appropriate action for the menu item selected. 
  234.     comment: 
  235.     parameters:
  236.     return:
  237.     date: 1989
  238.     author: Jim Charlton
  239.     modifications:
  240.         1995: C.Moreau: 
  241. */
  242. static void handle_edit(int itemid)
  243. {
  244.     if (thefrontwin && !thefrontwin->form)
  245.     {
  246.         switch(itemid)
  247.         {
  248.             case START:
  249.                 start_mark(thefrontwin);
  250.                 break;
  251.             case END:
  252.                 end_mark(thefrontwin);
  253.                 break;
  254.             case CLEAR:
  255.                 clear_marks(thefrontwin);
  256.                 break;
  257.             case SELECT_ALL:
  258.                 {    
  259.                     const long old_pos = thefrontwin->position;
  260.                     
  261.                     thefrontwin->position = 0;    
  262.                     start_mark(thefrontwin);
  263.                     thefrontwin->position = thefrontwin->flen-1;    
  264.                     end_mark(thefrontwin);
  265.                     thefrontwin->position = old_pos;
  266.                 }
  267.                 break;
  268.             case COPY    :
  269.                 if (thefrontwin->markson)
  270.                 {    
  271.                     copy(thefrontwin);
  272.                     clear_marks(thefrontwin);
  273.                     menu_ienable(menu, PASTE, ENABLE);
  274.                 }
  275.                 break;
  276.             case CUT    :
  277.                 if (thefrontwin->markson)
  278.                 {
  279.                     if (!thefrontwin->prot)
  280.                     {
  281.                         copy(thefrontwin);
  282.                         cutit(thefrontwin);
  283.                         send_vslid(thefrontwin);
  284.                         thefrontwin->changed = TRUE;
  285.                         clear_marks(thefrontwin);
  286.                         menu_ienable(menu, PASTE, ENABLE);
  287.                     }
  288.                     else
  289.                         rsc_alert(PROTECTED);
  290.                 }
  291.                 break;
  292.             case PASTE    :
  293.                 if (!thefrontwin->prot)
  294.                 {
  295.                     paste(thefrontwin);
  296.                     thefrontwin->changed = TRUE;
  297.                 }
  298.                 else
  299.                     rsc_alert(PROTECTED);
  300.                 break;
  301.             case ERASE    :
  302.                 if (thefrontwin->markson)
  303.                 {
  304.                     if (!thefrontwin->prot)
  305.                     {
  306.                         cutit(thefrontwin);
  307.                         send_vslid(thefrontwin);
  308.                         thefrontwin->changed = TRUE;
  309.                         clear_marks(thefrontwin);
  310.                     }
  311.                     else
  312.                         rsc_alert(PROTECTED);
  313.                 }
  314.                 break;
  315.             case INSERT :
  316.                 ins ^= TRUE;
  317.                 update_menu();
  318.                 break;
  319.             case PROTECT :
  320.                 thefrontwin->prot ^= TRUE;
  321.                 update_menu();
  322.                 break;
  323.         }
  324.     }
  325. }
  326.  
  327. /*
  328.     name: handle_search
  329.     utility:  
  330.     comment: 
  331.     parameters:
  332.     return:
  333.     date: 1989
  334.     author: Jim Charlton
  335.     modifications:
  336.         1995: C.Moreau: 
  337. */
  338. static void handle_search(int itemid)
  339. {
  340.     if (thefrontwin)
  341.     {
  342.         switch(itemid)
  343.         {
  344.             case GO_POS:
  345.                 open_dialog(DPOS);
  346.                 break;
  347.             case FIND:
  348.             case REPLACE:
  349.                 open_dialog(DSEARCH);
  350.                 break;
  351.             case FINDAGAIN:
  352.                 break;
  353.             case REPLACEAGAIN:
  354.                 break;
  355.         }
  356.     }
  357. }
  358.  
  359. /*
  360.     name: handle_windows
  361.     utility:  
  362.     comment: 
  363.     parameters:
  364.     return:
  365.     date: 1989
  366.     author: Jim Charlton
  367.     modifications:
  368.         1995: C.Moreau: 
  369. */
  370. static void handle_windows(int itemid)
  371. {
  372.     if (thefrontwin)
  373.     {
  374.         switch(itemid) 
  375.         {
  376.             case ROTATE            :
  377.                 window_rot();
  378.                 break;
  379.             case TILE_HORIZ     :
  380.                 window_tile(TRUE);
  381.                 break;
  382.             case TILE_VERTIC    :
  383.                 window_tile(FALSE);
  384.                 break;
  385.             case STACK            :
  386.     
  387.                 break;
  388.             case ICONIFY        :
  389.                 window_iconify(thefrontwin);
  390.                 break;
  391.             case UNICONIFY        :
  392.                 window_uniconify(thefrontwin);
  393.                 break;
  394.             case ICONIFY_ALL        :
  395.                 window_iconify_all();
  396.                 break;
  397.         }
  398.     }
  399. }
  400.  
  401. /*
  402.     name: handle_options
  403.     utility:  
  404.     comment: 
  405.     parameters:
  406.     return:
  407.     date: 13 may 96
  408.     author: C. Moreau
  409.     modifications: 
  410. */
  411. static void handle_options(int itemid)
  412. {
  413.     switch(itemid) 
  414.     {
  415.         case BLACK_WHITE    :
  416.             black_white ^= TRUE;
  417.             send_redraw_all();        /* redraw all windows */
  418.             break;
  419.         case GROW_SHRINK    :
  420.             grow_shrink ^= TRUE;
  421.             break;
  422.         case INFO_HEXA        :
  423.             info_hexa ^= TRUE;
  424.             break;
  425.         case CLIPBOARD        :
  426.         case SAVEOPTS        :
  427.         case LOADOPTS        :
  428.             break;
  429.     }
  430.     update_menu();
  431. }
  432.  
  433. /*
  434.     name: init_menu
  435.     utility: sets up menu bar
  436.     comment: 
  437.     parameters: none
  438.     return: none
  439.     date: 1995
  440.     author: C.Moreau
  441.     modifications:
  442. */
  443. void init_menu(void)
  444. {
  445.     char *string;
  446.     
  447.     rsrc_gaddr(R_STRING, S_MODERP, &string);
  448.     strcpy(moderp, string);
  449.     rsrc_gaddr(R_STRING, S_MODEIN, &string);
  450.     strcpy(modein, string);
  451.  
  452.     rsrc_gaddr(R_TREE, MENU, &menu);
  453.  
  454.     if (ver_aes >= 0x410)
  455.     {
  456.         menu_ienable(menu, ICONIFY, ENABLE);
  457.         menu_ienable(menu, UNICONIFY, ENABLE);
  458.         menu_ienable(menu, ICONIFY_ALL, ENABLE);
  459.     }
  460.     else
  461.     {
  462.         menu_ienable(menu, ICONIFY, DISABLE);
  463.         menu_ienable(menu, UNICONIFY, DISABLE);
  464.         menu_ienable(menu, ICONIFY_ALL, DISABLE);
  465.     } 
  466.  
  467.     menu_bar(menu, MENU_INSTALL);
  468.     update_menu();
  469. }
  470.  
  471. /*
  472.     name: update_menu
  473.     utility: update the menu bar with globals vars
  474.     comment: 
  475.     parameters: none
  476.     return: none
  477.     date: 11 may 96
  478.     author: C.Moreau
  479.     modifications:
  480. */
  481. void update_menu(void)
  482. {
  483.     menu_icheck(menu, BLACK_WHITE, (black_white?CHECK:UNCHECK));
  484.     menu_icheck(menu, GROW_SHRINK, (grow_shrink?CHECK:UNCHECK));
  485.     menu_icheck(menu, INFO_HEXA, (info_hexa?CHECK:UNCHECK));
  486.     menu_text(menu, INSERT, (ins?moderp:modein));
  487.  
  488.     if (thefrontwin && !thefrontwin->form)
  489.     {
  490.         const prot = thefrontwin->prot;
  491.         
  492.          if (thefrontwin->markson)
  493.          {
  494.             menu_ienable(menu, CUT, ENABLE);
  495.             menu_ienable(menu, COPY, ENABLE);
  496.             menu_ienable(menu, ERASE, ENABLE);
  497.         }
  498.         else
  499.         {
  500.             menu_ienable(menu, CUT, DISABLE);
  501.             menu_ienable(menu, COPY, DISABLE);
  502.             menu_ienable(menu, ERASE, DISABLE);
  503.         }
  504.         
  505.         menu_icheck(menu, PROTECT, prot?CHECK:UNCHECK);
  506.     }
  507. }
  508.